<?php 
class LoginControl extends Control{

    public function login()
    {
        if(IS_POST){
            if(!$_POST['key']){
                $this->error('验证码错误请重新输入');
                exit;
            }
            $username = $_POST['username'];
            $password = md5($_POST['password']);
            $db = M('admin');
            $data = $db->where("username='".$username."'")->find();
            if($data) 
            {
                if($data['password'] == $password)
                {
                    $_SESSION['admin'] = array();
                    $_SESSION['admin']['username'] = $data['username'];
                    $_SESSION['admin']['aid'] = $data['aid'];
                    go("Index/index");
                }
                $this->error('密码错误');
            }
            $this->error('用户名不存在');    
        }else{
            $this->display();
        }
    }

    public function out()
    {
        $_SESSION['admin'] = array();
        $this->success('退出成功','Index/index');
    }

    public function showCode(){
        $code = new code(80,32);
        $code->show();
    }

    public function checkCode(){
        $result = array();
        if($_SESSION['code'] == $_POST['code']){
            $result['status'] = true;
            $result['msg'] = '验证码正确';
        }else{
            $result['status'] = false;
            $result['msg'] = '验证码错误';
        }
        echo  json_encode($result);
        exit;
    }


}












 ?>